package day07.ThreadDemo;

/*
 * Author: JacksonCoder
 * FileName: synchronizedDemo
 * Version: 1.0.0
 * Date: 2025/4/14
 */

public class synchronizedDemo {

    private int count = 0;

    public synchronized void add(){
        count++;
        System.out.println(Thread.currentThread().getName() + " : " + count);
    }

    public  void  printCount(){
        System.out.println("the count end is:" + count);
    }

    public static void main(String[] args) {
        synchronizedDemo demo = new synchronizedDemo();
        try{
            for (int i = 0; i < 5; i++) {
                new Thread(() -> {
                    for (int j = 0; j < 5; j++) {
                        demo.add();
                    }
                }).start();
            }
        }catch ( Exception e){
            e.printStackTrace();
        }
    }

}
